package club.zhilin.guli.service.base.exception;

import club.zhilin.guli.common.base.result.CommonResultCodeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

/**
 * 全局异常类
 *
 * @author zhilin
 * @since 2022/1/20 18:55
 */
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
public class GlobalException extends RuntimeException {

    private static final long serialVersionUID = -7025877914245687777L;

    private Integer code;

    public GlobalException() {
        super();
    }

    public GlobalException(String message) {
        super(message);
    }

    public GlobalException(String message, Integer code) {
        super(message);
        this.code = code;
    }

    public GlobalException(CommonResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    public GlobalException(String message, Throwable cause) {
        super(message, cause);
    }

    public GlobalException(Throwable cause) {
        super(cause);
    }

    protected GlobalException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

    @Override
    public String toString() {
        return "GlobalException{" +
                "code=" + code +
                ",message=" + this.getMessage() +
                '}';
    }
}
